import { createRouter, createWebHashHistory } from 'vue-router'

// 布局组件
import Layout from '@/layouts/Index.vue'

// 基础路由配置
const routes = [
  {
    path: '/',
    redirect: '/login',
  },
  {
    path: '/login',
    name: 'login',
    component: () => import('@/views/Login/Index.vue'),
    meta: {
      title: '登录',
      public: true,
    },
  },
  // 404页面应该始终存在
  {
    path: '/:pathMatch(.*)*',
    name: 'not-found',
    component: () => import('@/views/NotFound/Index.vue'),
    meta: {
      title: '页面未找到',
      public: true,
    },
  },
  {
    path: '/home',
    name: '首页',
    component: Layout,
    meta: {
      title: '首页',
      public: true,
    },
    redirect: '/overview',
    children: [
      {
        path: '/overview',
        name: 'overview',
        component: () => import('@/views/Analysis/Overview.vue'),
        meta: {
          title: '概览',
        },
      },
      {
        path: '/stock',
        name: 'stock',
        component: () => import('@/views/Analysis/Stock.vue'),
        meta: {
          title: '股票',
        },
      },
      {
        path: '/fund',
        name: 'fund',
        component: () => import('@/views/Analysis/Fund.vue'),
        meta: {
          title: '基金',
        },
      },
      {
        path: '/dividend',
        name: 'dividend',
        component: () => import('@/views/Analysis/Dividend.vue'),
        meta: {
          title: '股息',
        },
      },
    ],
  },
]

// 创建路由实例
const router = createRouter({
  history: createWebHashHistory(import.meta.env.BASE_URL),
  routes,
})

export default router
